package com.gopay.scheduler.service.mobileproduct.waproduct.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.gopay.common.cps.dao.wallet.WaProductDao;
import com.gopay.scheduler.service.mobileproduct.waproduct.WaProductService;

@Service("waProductService")
public class WaProductServiceImpl implements WaProductService {
	
	@Resource(name = "waProductDao")
	private WaProductDao waProductDao;

	@Override
	public void updateStatusByCron() {
		StringBuilder sql = new StringBuilder();
		sql.append(" update WA_PRODUCT ");
		sql.append("    set VALIDITY_STATUS = '1', UPDATE_TIME = sysdate ");
		sql.append("  where VALIDITY_STATUS = '2' ");
		sql.append("    and VALIDITY_START_TIME < sysdate ");
		waProductDao.updateBySql(sql.toString(), null);
		
		sql.delete(0, sql.length());
		sql.append(" update WA_PRODUCT ");
		sql.append("    set VALIDITY_STATUS = '0', UPDATE_TIME = sysdate ");
		sql.append("  where VALIDITY_STATUS = '1' ");
		sql.append("    and VALIDITY_END_TIME < sysdate ");
		waProductDao.updateBySql(sql.toString(), null);
		
		sql.delete(0, sql.length());
		sql.append(" update WA_PRODUCT ");
		sql.append("    set DISCOUNT_STATUS = '1', UPDATE_TIME = sysdate ");
		sql.append("  where DISCOUNT_STATUS = '2' ");
		sql.append("    and DISCOUNT_START_TS < sysdate ");
		waProductDao.updateBySql(sql.toString(), null);
		
		sql.delete(0, sql.length());
		sql.append(" update WA_PRODUCT ");
		sql.append("    set DISCOUNT_STATUS = '0', UPDATE_TIME = sysdate ");
		sql.append("  where DISCOUNT_STATUS = '1' ");
		sql.append("    and DISCOUNT_END_TS < sysdate ");
		waProductDao.updateBySql(sql.toString(), null);
	}

}
